package logic

import (
	"context"
	"jd_mall_users/api/internal/svc"
	"jd_mall_users/api/internal/types"
	"jd_mall_users/user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateAvatarLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateAvatarLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateAvatarLogic {
	return &UpdateAvatarLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateAvatarLogic) UpdateAvatar(req *types.UpdateAvatarRequest) (resp *types.Response, err error) {

	_, err = l.svcCtx.UserSrv.UpdateAvatar(l.ctx, &user.UpdateAvatarRequest{
		AvatarUrl: req.AvatarUrl,
	})
	if err != nil {
		return &types.Response{
			Code: -1,
			Msg:  "修改失败",
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: -1,
		Msg:  "修改成功",
		Data: nil,
	}, nil
}
